/*
 * CircuitPanel.hpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   CircuitPanel.hpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   27 jan 2013
 */
#ifndef CIRCUITPANEL_HPP
#define CIRCUITPANEL_HPP

#include <wx/wx.h>
#include <boost/shared_ptr.hpp>

#include "Resistance.hpp"
#include "Voltage.hpp"
#include "AdcValue.hpp"
#include "AdcVisitor.hpp"
#include "CircuitVisitor.hpp"

using boost::shared_ptr;

namespace tltgen {

  class Circuit;
  class VoltageDividerCircuit;
  class AnalogToDigitalConverter;
  class LinearAdc;
  class CircuitPanel : public wxPanel, public AdcVisitor, public CircuitVisitor {
  public:
    CircuitPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, 
		 long style = wxTAB_TRAVERSAL, const wxString& name = wxT("CircuitPanel"));
    virtual ~CircuitPanel();

    virtual unsigned int getNbAdcBits() const;
    virtual void setNbAdcBits(unsigned int value);
    virtual Voltage getAdcReferenceVoltage() const;
    virtual void setAdcReferenceVoltage(Voltage value);
    virtual void setAdcValues(const shared_ptr<AnalogToDigitalConverter const>& adc);

    virtual Voltage getCircuitInputVoltage() const;
    virtual void setCircuitInputVoltage(Voltage value);
    virtual Resistance getDividerResistance() const;
    virtual void setDividerResistance(Resistance value);
    virtual bool getUseParallelResistor() const;
    virtual void setUseParallelResistor(bool value);
    virtual Resistance getParallelResistance() const;
    virtual void setParallelResistance(Resistance value);
    virtual void setCircuitValues(const shared_ptr<Circuit const>& circuit);
  
    virtual shared_ptr<AnalogToDigitalConverter> createAnalogToDigitalConverter() const;
    virtual shared_ptr<Circuit> createCircuit() const;

  protected:
    DECLARE_EVENT_TABLE();

    virtual void updateParallelResistanceEnabled();
    virtual void onUseParallelResistorChanged(wxCommandEvent& event);

    virtual wxString formatNbAdcBits(unsigned int value) const;
    virtual wxString formatVoltage(Voltage value) const;
    virtual wxString formatResistance(Resistance value) const;

    virtual unsigned int getValueAsUnsignedInt(const wxString& string) const;
    virtual double getValueAsDouble(const wxString& string) const;

    friend class LinearAdc;
    virtual void visit(const LinearAdc* adc);
    friend class VoltageDividerCircuit;
    virtual void visit(const VoltageDividerCircuit* circuit);

    wxTextCtrl* txtNbAdcBits;
    wxTextCtrl* txtAdcReferenceVoltage;

    wxTextCtrl* txtCircuitInputVoltage;
    wxTextCtrl* txtDividerResistance;
    wxCheckBox* chkUseParallelResistor;
    wxTextCtrl* txtParallelResistance;
  };

  enum {
    ID_UseParallelResistor = 1,
  };
}

#endif
